package com.shareppy.norman.util;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import android.content.ContentValues;

import com.shareppy.utils.conversion.Converter;

public class MapToContentValuesConverter implements Converter<Map<String, Object>, ContentValues> {

	@Override
	public ContentValues convert(Map<String, Object> input) throws Exception {
		ContentValues cv = new ContentValues();
		Set<Entry<String, Object>> entrySet = input.entrySet();
		for (Entry<String, Object> entry : entrySet) {
			Object value = entry.getValue();
			if( value instanceof Integer ){
				cv.put(entry.getKey(), (Integer)value);
			}else if(value instanceof Long){
				cv.put(entry.getKey(), (Long)value);
			}else if(value instanceof Float){
				cv.put(entry.getKey(), (Float)value);
			}else if(value instanceof Double){
				cv.put(entry.getKey(), (Double)value);
			}else if(value instanceof String){
				cv.put(entry.getKey(), (String)value);
			}
		}
		return cv;
	}
}